package com.gateway.common.dto;


import com.gateway.common.enums.ApiStatusEnum;
import com.gateway.common.enums.AuthenticationTypeEnum;
import com.gateway.common.enums.AuthorizationTypeEnum;

import java.io.Serializable;

/**
 * @program: ahcloud-gateway
 * @description:
 * @author: YuKai Fan
 * @create: 2023/2/20 23:17
 **/
public class ApiDefinition implements Serializable {
    private static final long serialVersionUID = -2032491110731433753L;

    /**
     * api编码
     */
    private String apiCode;

    /**
     * api path
     */
    private String path;

    /**
     * 是否需要认证
     */
    private Boolean authentication;

    /**
     * 是否需要鉴权
     */
    private Boolean authorization;

    /**
     * 是否需要csrf
     */
    private Boolean csrf;

    /**
     * 是否开放
     */
    private Boolean open;

    /**
     * 模块
     */
    private String module;

    /**
     * rpc类型
     */
    private String rpcType;

    /**
     * 是否可用
     */
    private ApiStatusEnum status;

    /**
     * 环境变量
     */
    private String env;

    /**
     * 认证类型
     */
    private AuthenticationTypeEnum authenticationType;

    /**
     * 认证类型
     */
    private AuthorizationTypeEnum authorizationType;

    public String getApiCode() {
        return apiCode;
    }

    public void setApiCode(String apiCode) {
        this.apiCode = apiCode;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Boolean getAuthentication() {
        return authentication;
    }

    public void setAuthentication(Boolean authentication) {
        this.authentication = authentication;
    }

    public Boolean getAuthorization() {
        return authorization;
    }

    public void setAuthorization(Boolean authorization) {
        this.authorization = authorization;
    }

    public Boolean getCsrf() {
        return csrf;
    }

    public void setCsrf(Boolean csrf) {
        this.csrf = csrf;
    }

    public Boolean getOpen() {
        return open;
    }

    public void setOpen(Boolean open) {
        this.open = open;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getRpcType() {
        return rpcType;
    }

    public void setRpcType(String rpcType) {
        this.rpcType = rpcType;
    }

    public ApiStatusEnum getStatus() {
        return status;
    }

    public void setStatus(ApiStatusEnum status) {
        this.status = status;
    }

    public String getEnv() {
        return env;
    }

    public void setEnv(String env) {
        this.env = env;
    }

    public AuthenticationTypeEnum getAuthenticationType() {
        return authenticationType;
    }

    public void setAuthenticationType(AuthenticationTypeEnum authenticationType) {
        this.authenticationType = authenticationType;
    }

    public AuthorizationTypeEnum getAuthorizationType() {
        return authorizationType;
    }

    public void setAuthorizationType(AuthorizationTypeEnum authorizationType) {
        this.authorizationType = authorizationType;
    }


    public static final class Builder {
        private String apiCode;
        private String path;
        private Boolean authentication;
        private Boolean authorization;
        private Boolean csrf;
        private Boolean common;
        private Boolean open;
        private String module;
        private String rpcType;
        private ApiStatusEnum status;
        private String env;
        private AuthenticationTypeEnum authenticationType;
        private AuthorizationTypeEnum authorizationType;

        private Builder() {
        }

        public static Builder builder() {
            return new Builder();
        }

        public Builder apiCode(String apiCode) {
            this.apiCode = apiCode;
            return this;
        }

        public Builder path(String path) {
            this.path = path;
            return this;
        }

        public Builder authentication(Boolean authentication) {
            this.authentication = authentication;
            return this;
        }

        public Builder authorization(Boolean authorization) {
            this.authorization = authorization;
            return this;
        }

        public Builder csrf(Boolean csrf) {
            this.csrf = csrf;
            return this;
        }

        public Builder open(Boolean open) {
            this.open = open;
            return this;
        }

        public Builder module(String module) {
            this.module = module;
            return this;
        }

        public Builder rpcType(String rpcType) {
            this.rpcType = rpcType;
            return this;
        }

        public Builder status(ApiStatusEnum status) {
            this.status = status;
            return this;
        }

        public Builder env(String env) {
            this.env = env;
            return this;
        }

        public Builder authenticationType(AuthenticationTypeEnum authenticationType) {
            this.authenticationType = authenticationType;
            return this;
        }

        public Builder authorizationType(AuthorizationTypeEnum authorizationType) {
            this.authorizationType = authorizationType;
            return this;
        }

        public ApiDefinition build() {
            ApiDefinition apiDefinition = new ApiDefinition();
            apiDefinition.setApiCode(apiCode);
            apiDefinition.setPath(path);
            apiDefinition.setAuthentication(authentication);
            apiDefinition.setAuthorization(authorization);
            apiDefinition.setCsrf(csrf);
            apiDefinition.setOpen(open);
            apiDefinition.setModule(module);
            apiDefinition.setRpcType(rpcType);
            apiDefinition.setStatus(status);
            apiDefinition.setEnv(env);
            apiDefinition.setAuthenticationType(authenticationType);
            apiDefinition.setAuthorizationType(authorizationType);
            return apiDefinition;
        }
    }
}
